﻿@using Website.CRUDServices
@using Location = Website.Models.Domain.Location
@using Profile = Website.Models.Domain.Profile
@using Region = Website.Models.Domain.Region
@{
    this.ViewBag.Title = "Forretningsudvikling";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Regions = this.ViewData["Regions"] as List<Region>;
    var allTopics = this.ViewData["DiscussionTopics"] as List<Topic>;
    var Projects = this.ViewData["Projects"] as List<Project>;
    var Profiles = this.ViewData["Profiles"] as Website.Models.ViewModels.ProfilesView;
    Guid otherId = Guid.Empty;

    // errorhandling
    var errorMsg = new HtmlString(string.Empty);
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as MvcHtmlString;
    }

}


<script type="text/javascript">
    //toggle script
    function toggle(id) {
        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }
</script>

<script>
    $(function() {
        $("#datepicker").datepicker();
    });
</script>

@using (this.Html.BeginForm())
{
    <div class="error">
        @errorMsg
    </div>

    // date
    <div class="formBullet">Dato*</div>
    <input type="text" id="datepicker" name="datepicker" readonly="readonly" value="" />

    // location
    <div class="formBullet">Lokation</div>
    <div class="formEntry">
        <select name="Location" id="Locations">
            <option value="@Guid.Empty">Vælg en lokation</option>
            @foreach (Location loc in Profiles.Locations.OrderBy(x => x.Name))
            {
                <option value="@loc.ID">@loc.Name</option>
            }
        </select>
    </div>

    // ownerProjects chooser
    <div class="formBullet">Alle projekter tilknyttet </div>
    <div class="formEntry">
        <select multiple="multiple" name="OwnerProjects" id="OwnerProjects">
            @foreach (Project proj in Projects)
            {
                <option value="@proj.ID">@proj.Name</option>
            }
        </select>
    </div>

    // profiles chooser
    <div class="formBullet">Profiler</div>
    <div class="formEntry">
        <select multiple="multiple" name="profilesSelect" id="profilesSelect">
            @foreach (Profile prof in Profiles.Profiles)
            {
                <option value="@prof.ID">@prof.Name</option>
            }
        </select>
    </div>



    // talks chooser
    <div class="formBullet">Specificeret snak</div>
    <div class="formEntry">
        <select multiple="multiple" name="talksSelect" id="talksSelect">
            @foreach (Topic top in allTopics)
            {
                if (top.Title == "Andet")
                {
                    otherId = top.ID;
                }

                <option value="@top.ID">@top.Title</option>
            }
        </select>
    </div>
    <br />
    <br />

    // field for specifying "andet"
    <div class="formEntry open_hidden" id="andet_holder">
        <div class="formBullet">Specificér andet</div>
        <textarea name="Andet"></textarea>
    </div>
    
        // status
    <div class="formBullet">Beskrivelse:</div>
    <div class="formEntry">
        <textarea name="Status"></textarea>
    </div>

    
    // additional comments
    <div class="formBullet"><input type="checkbox" onclick=" toggle('Comments_holder'); " name ="comments_check" value ="Ja"> Yderligere kommentarer?  <br/></div>
    <div class="formEntry open_hidden" id="Comments_holder">
        <textarea name="Comments"></textarea>
    </div>

    <div class="buttonHolder">
        <input type="submit" value="Opret" /></div>
}

<script>

    @*
        Og nu da det er rykket herned kan du bruge @otherID til at lave dit script.
        Alt hvad der bliver skrevet med et @ bliver parset (server-side) før siden er endeligt loadet.
    *@
    $(function() {
        $('#profilesSelect').multiSelect();
        $('#OwnerProjects').multiSelect();
     
        //choosing "andet" will pop up an additional text-box for input on the subject

        $('#talksSelect').multiSelect({
            afterSelect: function(value) {
                if (value == "@otherId.ToString()") {
                    toggle("andet_holder");
                }
            },

            afterDeselect: function(value) {
                if (value == "@otherId.ToString()") {
                    toggle("andet_holder");
                }
            }
        });
       
    });
</script>


